package com.calm.cdemo.anim;

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;
import android.widget.TextView;

import com.calm.cdemo.R;
import com.calm.cdemo.base.BaseActivity;

/**
 * Create by Calm
 * 2020/3/3 15:29
 * 补间动画(平移、旋转、缩放、透明)
 * 补间动画资源存放位置 res/anim  访问时R.anim.xxx.xml
 */
public class TweenAnim extends BaseActivity implements View.OnClickListener {
    private TextView tvText;
    @Override
    protected void init() {
        tvText = findViewById(R.id.anim_tv_text);
        findViewById(R.id.animScale).setOnClickListener(this);
        findViewById(R.id.animAlpha).setOnClickListener(this);
        findViewById(R.id.animRoate).setOnClickListener(this);
        findViewById(R.id.animTranslate).setOnClickListener(this);
        findViewById(R.id.animSet).setOnClickListener(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.tweenanim;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.animScale:
                doScaleAnim();
                break;
            case R.id.animAlpha:
                doAplhaAnim();
                break;
            case R.id.animRoate:
                doRoateAnim();
                break;
            case R.id.animTranslate:
                doTranslateAnim();
                break;
            case R.id.animSet:
                doSetAnim();
                break;
        }
    }
    private void doScaleAnim(){
        //以xml的方式引入
//        Animation animation = AnimationUtils.loadAnimation(mActivity,R.anim.scalesimple);
//        tvText.startAnimation(animation);
        //java代码实例化
        ScaleAnimation scaleAnimation = new ScaleAnimation(0.0f,2.0f,0.0f,2.0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
        scaleAnimation.setDuration(2000);
        tvText.startAnimation(scaleAnimation);
    }
    private void doAplhaAnim(){
        Animation animation = AnimationUtils.loadAnimation(mActivity,R.anim.alphasimple);
        tvText.startAnimation(animation);
    }
    private void doRoateAnim(){
        Animation animation = AnimationUtils.loadAnimation(mActivity,R.anim.roatesimple);
        tvText.startAnimation(animation);
    }
    private void doTranslateAnim(){
        Animation animation = AnimationUtils.loadAnimation(mActivity,R.anim.translatesimple);
        tvText.startAnimation(animation);
    }
    private void doSetAnim(){
        Animation animation = AnimationUtils.loadAnimation(mActivity,R.anim.setsimple);
        tvText.startAnimation(animation);
    }
}
